package com.wanmait.recruitment.controller;

import com.github.pagehelper.PageInfo;
import com.wanmait.recruitment.pojo.Nations;
import com.wanmait.recruitment.pojo.Stage;
import com.wanmait.recruitment.service.ConfigService;
import com.wanmait.recruitment.service.StageService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/manage/stage")
public class StageController {
    @Resource
    private StageService stageService;
    @Resource
    private ConfigService configService;
    @RequestMapping("list")
    public void list()
    {

    }
    @RequestMapping("listdata")
    public void listdata(Integer pagernum, Model model)
    {
        int pageNum;
        try {
            pageNum = pagernum;
        } catch (NumberFormatException e) {
            pageNum = 1;
        }
        //每页显示条数
        int pageSize;
        try {
            pageSize = Integer.parseInt(configService.getValueByKey("job_list_count"));
        } catch (NumberFormatException e) {
            pageSize = 8;
        }
        PageInfo<Stage> pageInfo = stageService.findPage(pageNum,pageSize);
        List<Stage>stages = pageInfo.getList();
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("stages",stages);

    }
    @RequestMapping("delete")
    @ResponseBody
    public void delete(Integer id)
    {
        stageService.delete(id);
    }
    @PostMapping("insert")
    @ResponseBody
    public void insert(String title)
    {
        Stage stage = new Stage();
        stage.setStageName(title);
        stageService.insert(stage);
    }
}
